package Compare;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;


/**
 * @Program: CompareFiles
 * @Description:
 * @Author: zqs
 * @Create： 2021-07-14-14:23
 */
public class MainTest {
    public static void main(String[] args) throws IOException {
        File file1 = new File("");
        File file2 = new File("");

        System.out.println("文件长度（大小）对比===>");
        System.out.println(file1.getName()+"    长度："+file1.length());
        System.out.println(file2.getName()+"    长度："+file2.length());
        System.out.println("对比结果:"+(file1.length() == file2.length() ?"文件相同" : "文件不相同"));

        System.out.println("文件内容长度输出===>");
        FileInputStream fileA = new FileInputStream(file1);
        FileInputStream fileB = new FileInputStream(file2);
        System.out.println(fileA.available());
        System.out.println(fileB.available());
            System.out.println(fileA.available() == fileB.available() ? "文件相同" : "文件不相同");

        System.out.println("文件内容对比输出===>");
        String results= CompareFile.content(file1,file2);
            System.out.println(results);

/*
        System.out.println("\n文件指纹md5输出===>");
        String str1 = CompareFile.getFileMD5(file1);
        String str2 = CompareFile.getFileMD5(file2);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str1.compareTo(str2) == 0 ? "文件相同" : "文件不相同");
*/

        System.out.println("\n文件指纹sha-1对比===>");
        String sha1 = CompareFile.getFileSha1(file1);
        String sha2 = CompareFile.getFileSha1(file2);
        System.out.println(file1.getName()+"    sha-1指纹："+sha1);
        System.out.println(file2.getName()+"    sha-1指纹："+sha2);
        System.out.println("对比结果:"+(sha1.compareTo(sha2) == 0 ? "文件相同" : "文件不相同"));

/*        System.out.println("通过JDK 14 + 方法mismatch对比结果输出===>");
            Path path1 = Path.of(String.valueOf(file1));
            Path path2 = Path.of(String.valueOf(file2));
            long result = Files.mismatch(path1, path2);
            // -1 相等，0 不等，大于0 不等
            System.out.println(result);*/
        System.out.println("\nDigestUtils，文件md5值指纹对比===>");
        String utilsRes1 = CompareFile.getMd5(file1);
        String utilsRes2 = CompareFile.getMd5(file2);
        System.out.println(file1.getName()+"    MD5指纹："+utilsRes1);
        System.out.println(file2.getName()+"    MD5指纹："+utilsRes2);
        System.out.println("对比结果:"+(utilsRes1.compareTo(utilsRes2) == 0 ? "文件相同" : "文件不相同"));
    }
}
